<template>
  <a-modal
    :title="title"
    width="80%"
    :visible="visible"
    :footer="null"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-card :bordered="false">
      <detail-list title="基本信息">
        <detail-list-item term="用户姓名">{{sellerCashInfo.username}}</detail-list-item>
        <detail-list-item term="联系电话">{{sellerCashInfo.mobile}}</detail-list-item>
        <detail-list-item term="待提现金额">{{sellerCashInfo.availableCash == null?0:sellerCashInfo.availableCash / 100}}</detail-list-item>
        <detail-list-item term="已提现金额">{{sellerCashInfo.hasCash == null?0:sellerCashInfo.hasCash / 100}}</detail-list-item>
        <detail-list-item term="提现中金额">{{sellerCashInfo.cashingMoney == null?0:sellerCashInfo.cashingMoney / 100}}</detail-list-item>
      </detail-list>
      <a-divider style="margin-bottom: 32px"/>
      <div class="title">订单详情</div>
      <a-table
        style="margin-bottom: 24px"
        :columns="goodsColumns"
        :dataSource="orderDetails"
        :scroll="{ y: 240 }"
      >
      </a-table>
      <div class="examples" >
        <a-button style="margin-left:30px;" size="large" @click="confirmCashInfo(sellerCashInfoId)"  :disabled="successButton" type="primary">提现</a-button>
        <a-button style="margin-left:40px;" size="large" @click="closeTab()"  type="danger">取消</a-button>

      </div>
    </a-card>
  </a-modal>
</template>

<script>
  import { postAction,getAction } from '@/api/manage'
  import STable from '@/components/table/'
  import DetailList from '@/components/tools/DetailList'
  const DetailListItem = DetailList.Item

  export default {
    name: 'templateDetails',
    components: {
      DetailList,
      DetailListItem,
      STable
    },
    data() {
      return {
        sellerCashInfo:{},
        orderDetails:[],
        successButton: false,
        sellerCashInfoId:{},
        goodsColumns: [
          {
            title: '订单编号',
            dataIndex: 'id',
            key: 'id'
          },
          {
            title: '单价',
            dataIndex: 'buyPrice',
            key: 'buyPrice',
            customRender: text => {
              if(text == null || text == 0){
                return 0
              }else {
                return text  / 100
              }
            }
          },
          {
            title: '优惠金额',
            dataIndex: 'discountPrice',
            key: 'discountPrice',
            customRender: text => {
              if(text == null || text == 0){
                return 0
              }else {
                return text  / 100
              }
            }
          },
          {
            title: '最终金额',
            dataIndex: 'presentPrice',
            key: 'presentPrice',
            customRender: text => {
              if(text == null || text == 0){
                return 0
              }else {
                return text  / 100
              }
            }
            // align: 'right'
          },
          {
            title: '付款时间',
            dataIndex: 'paymentTime',
            key: 'paymentTime'
            // align: 'right'
          },
          {
            title: '成交时间',
            dataIndex: 'closingTime',
            key: 'closingTime'
            // align: 'right'
          }
        ],
        visible: false,
        title: '提现详情',
        confirmLoading: false,
      }
    },
    created(){
    },
    methods: {
      show(id) {
        let that_ = this
        let param = {id:id}
        that_.sellerCashInfoId = id;
        this.visible = true
        this.orderDetails = []
        this.$nextTick(function () {
          getAction("/cashInfoLog/queryById",param)
            .then(res => {
              if(res.success){
                for(let i = 0; i<res.result.length;i++){
                    this.sellerCashInfo = res.result[i]
                    this.orderDetails.push(res.result[i].orderDetails[0])
                }

              }else{
                this.$notification[ 'error' ]({
                  message: "错误提示",
                  description:res.message,
                  duration: 4,
                });
              }
            })
            .catch(err => {
            });
        })
      },
      //同意
      confirmCashInfo(record){
        console.log("id：" + record)
        let obj = {sellerId:record};
        this.$nextTick(function () {
          postAction("/seller/merchant/administratorsCashMoney",obj)
            .then(res => {
              if (res.success) {
                this.$router.back()
                this.$notification.success({
                  message: '提现结果',
                  description: `提现 : `+"提现成功！",
                });
                this.successButton=true
              }else {
                this.$router.back()
                this.$notification.success({
                  message: '提现结果',
                  description: `提现 : `+"提现失败！",
                });
                this.successButton=false
              }

            }).catch(err => {
          });
        })
        this.closeTab()
      },
      close() {
        this.$emit('close')
        this.visible = false
      },
      handleOk() {
        this.close()
      },
      handleCancel() {
        this.close()
      },
      //关闭标签
      closeTab(){
        this.$emit('close')
        this.visible = false
      },
    }
  }
</script>

<style lang="less" scoped>
  .examples {
    text-align: center;
  }
</style>
